﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using AAA.Models;
using AAA.Db;
using AAA.Repository;

namespace AAA.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            var db=new DemoDb();
          // var person=db.Person.FirstOrDefault();
            /* var account=new BankAccount()
             {
                 Account="CCTV123456",
                 IsActiced=true,
                 IsDelected=false,
                 CreatedTime=DateTime.Now,
                 UpdatedTime=DateTime.Now,
                 CreatorId=0,
                 DisplayOrder=0,
                 PersonId=person.ID
             };
             db.BankAccount.Add(account);        //进行初次增加信息
             db.SaveChanges(); */


             /* var account=new BankAccount()
             {
                 Account="CCTV000000123456",
                 IsActiced=true,
                 IsDelected=false,
                 CreatedTime=DateTime.Now,
                 UpdatedTime=DateTime.Now,
                 CreatorId=0,
                 DisplayOrder=0,
                 PersonId=person.ID
             };
             db.BankAccount.Update(account);    //再次增加信息
             db.SaveChanges(); */ 

            /* var account=db.BankAccount.FirstOrDefault();
            account.Account="CCTT55555";
            account.UpdatedTime=DateTime.Now;   //不懂
             db.BankAccount.Update(account);
            db.SaveChanges();  */ 

            /* var account=db.BankAccount.FirstOrDefault();             
            db.BankAccount.Remove(account);  //删除account的信息
            db.SaveChanges();  */

           var accountRep=new EfRepository<BankAccount>();  //引用EfRepository中的EfRepository（）
           accountRep.Delect(3);  //删除数据库中ID=3的信息

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
